<?php

/*
 * Classe que controla o acesso aos dados
 *
 * @author erick chavez
 * @since 28/07/09
 */

class DataAccessObject{
	
	private $conn = null;
	private $table = null;
	private $id_field = null;
	private $fields = array();
	
	public function DataAccessObject(){
		$this->conn =& $GLOBALS['connectionDefault'];
	}
	
	public function setTable($table){
		$this->table = $table;
	}
	
	public function setFields($id_field, $fields){
		$this->id_field = $id_field;
		$this->fields = $fields;
	}
	
	public function setValue($field, $value){
		$this->fields[$field] = $value;
	}
	
	public function insert(){
		
		foreach($this->fields as $key=>$value){
			$this->fields[$key] = mysql_escape_string($value);
		}
		
		$query = sprintf("insert into ".$this->table." (%s) values('%s')", implode(',', array_keys($this->fields)), implode("', '", $this->fields));
		echo $query;die;
		return $this->conn->query($query);
	}
	
	public function update($where = null){}
	
	public function select_all($where = null, $order = null, $group = null){}
	
	public function select_by_id($id){}
	
	public function select($fields, $where = null, $order = null, $group = null){}
	
	public function getError(){
		return $this->conn->error;
	}
}